#ifndef EM80_ADC_HPP
#define EM80_ADC_HPP

#include "../packet_base.hpp"
#include "../payload_headers.hpp"
#include "../em80_payload_factory.h"
#include "../../v8stdint.h"

#include <memory>

namespace em80_driver
{

class ADC : public EM80PayloadBase
{
public:
    ADC(const EM80PacketPtr &packet) : EM80PayloadBase(packet, "ADC", false, 1) {}

    struct Data
    {
        Data() : value(0){}
        uint16_t value;
    };

    Data data;

    ~ADC() {}

    //not to be used directly by external source
    bool serialize()
    {
        // //TODO : is it directly control the raw data?
        // std::shared_ptr<Buffer> byteStream = std::make_shared<Buffer>(packet->payload(), packet->packet().second);
        // buildBytes(static_cast<uint8_t>(Header::ADC), *byteStream);
        // buildBytes(static_cast<uint8_t>(length), *byteStream);
        // buildBytes(data.value, *byteStream);

        return true;
    }

    bool deserialize()
    {
        std::vector<uint8_t> byteStream;

        byteStream.assign(packet->payload(), packet->payload() + static_cast<uint32_t>(length) + 2);


        //TODO: check them
        uint8_t header_id, length_packed;
        buildVariable(header_id, byteStream);
        buildVariable(length_packed, byteStream);
        if(header_id != Header::ADC) return false;
        if(length_packed != length) return false;

        buildVariable(data.value, byteStream);

        return true;
    }
};


} // namespace em80_driver

#endif /* EM80_ADC_HPP*/
